

Ext.define('Holo.store.Apps', {
    extend: 'Ext.data.Store',
    requires: 'Holo.model.App',
    model: 'Holo.model.App',
    
    actionAddingApp : false,
    
    listeners: {
        load : function(store, records, successful, operation, eOpts){
    
	    //console.log('load store');
        },
        
        add: function(store, records,  index,  eOpts){
            store.sync();
	    this.actionAddingApp = true;
        },
    
        update: function(store, record, operation,  eOpts){
            store.sync();
        },
	
	datachanged : function (store, eOpts ){
	    
	    //The currentApp id is not correctly update when it's create, so we re-define it with this datachanged event
	    // normaly when the server add a row it will return the DB id added, this action auto update the store
	    //and fire the "datachanged event", so if we try actionAddingApp we have can get back the id return by the server
	    //console.log(store.max('id'));
	    
	    //if the last sport add is not 0 -> we receive the id affect by the DB (the ajax is finish)
	    if((this.actionAddingApp) && (store.last().get('id')!=0)){
		this.actionAddingApp = false;
		GlobalData.currentApp = store.last();
	        GlobalData.currentController.screenUpdate();
		console.log('App officialy added, the currentApp is the last create');
	    }
	}
    }

});